package control

import (
	"net/http"
	"pro_cla_sql/model"
	"pro_cla_sql/util"
	"strconv"
)

func Sworksadd(w http.ResponseWriter, r *http.Request) {
	w.Header().Set(`Content-Type`, `application/json`)
	w.Header().Set(`Access-Control-Allow-Origin`, `*`)

	r.ParseForm()
	// map
	var sno = r.FormValue("sno")
	var sname = r.FormValue("sname")
	var content = r.FormValue("content")
	var teacher = r.FormValue("teacher")
	var acno = r.FormValue("course")
	var path = `E:\GoPath\src\pro_cla_sql` + r.FormValue("path")

	acid := sno[0:10]
	cid, _ := strconv.Atoi(acid)
	cno, _ := strconv.Atoi(acno)
	ok := model.Sworkadd(sno, sname, content, teacher, path, cno, cid)
	if ok {
		w.Write(util.NewResult(util.Success, "提交成功"))
		// w.Write([]byte(`添加成功`))
	} else {
		// w.Write([]byte(`添加失败`))
		w.Write(util.NewResult(util.Fail, "提交失败"))
	}

}
func Swork(w http.ResponseWriter, r *http.Request) {
	w.Header().Set(`Content-Type`, `application/json`)
	w.Header().Set(`Access-Control-Allow-Origin`, `*`)
	cid := CSno[0:10]
	println(cid[0:10])
	// print(sno)
	mod, err := model.SworksAll(cid)
	if err != nil {
		w.Write(util.NewResult(util.Fail, "作业信息查询失败"))
		return
	} else {
		w.Write(util.NewResult(util.Success, "作业信息查询成功", mod))
		return
	}

}
